<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">
	<xsl:apply-templates />
</xsl:template>

<xsl:template match="/Tree">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="TreeNode[@IsLeaf=0]">
  <div>
     <xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_Parent</xsl:attribute>
     <table border="0" cellspacing="0" cellpadding="0">
        <xsl:attribute name="width"><xsl:eval>getWidth(this)</xsl:eval></xsl:attribute>
        <tr>
  	<td valign="middle" nowrap="nowrap"><xsl:eval no-entities="yes">getImgs(this)</xsl:eval><a type="expand_icon"><xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_a</xsl:attribute>
  	    <xsl:attribute name="pos"><xsl:eval>isLast(this)</xsl:eval></xsl:attribute>
  	    <xsl:attribute name="expand">0</xsl:attribute>
  	    <xsl:attribute name="style">cursor:hand</xsl:attribute><img type="expand_icon">
                 <xsl:attribute name="src"><xsl:eval>getFirstImg(this,true)</xsl:eval></xsl:attribute>
  	       <xsl:attribute name="align">absmiddle</xsl:attribute>
  	       <xsl:attribute name="border">0</xsl:attribute>
  	    </img><img type="expand_icon">
               <xsl:attribute name="src"><xsl:eval>getSecImg(this,"folder1.gif")</xsl:eval></xsl:attribute>
	       <xsl:attribute name="oldsrc"><xsl:eval>getOpenSecImg(this,"folder1.gif")</xsl:eval></xsl:attribute>
  	       <xsl:attribute name="align">absmiddle</xsl:attribute>
  	       <xsl:attribute name="border">0</xsl:attribute></img>
  	   </a>
              <xsl:choose>
                 <xsl:when test="@url">
                   <a>
                       <xsl:if test="@target">
                         <xsl:attribute name="target"><xsl:value-of select="@target" /></xsl:attribute>
                       </xsl:if>
                       <xsl:if test="@action">
		          <xsl:attribute name="onclick"><xsl:value-of select="@action" /></xsl:attribute>
                       </xsl:if>
                     <xsl:attribute name="tabindex">-1</xsl:attribute>
                     <xsl:attribute name="href"><xsl:value-of select="@url" /></xsl:attribute>
  		     <span type="label" style="cursor:handle">
		         <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		         <xsl:attribute name="type">label</xsl:attribute>
			 <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		         <xsl:value-of select="@caption" />
     		     </span>
                  </a>
                </xsl:when>
  	      <xsl:when test="@action">
                  <a>
                    <xsl:attribute name="tabindex">-1</xsl:attribute>
  	            <xsl:attribute name="style">cursor:hand</xsl:attribute>
                    <xsl:attribute name="onclick"><xsl:value-of select="@action" /></xsl:attribute>
		    <xsl:attribute name="href">#</xsl:attribute>
                    <span type="label" style="cursor:handle">
		         <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		         <xsl:attribute name="type">label</xsl:attribute>
			 <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		         <xsl:value-of select="@caption" />
     		    </span>
                  </a>
                </xsl:when>
                <xsl:otherwise>
                   <span type="label" style="cursor:handle">
		         <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		         <xsl:attribute name="type">label</xsl:attribute>
			 <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		         <xsl:value-of select="@caption" />
     		   </span>
                </xsl:otherwise>
              </xsl:choose>
  	</td>
        </tr>
     </table>
    </div>
    <div>
       <xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_Child</xsl:attribute>
       <xsl:attribute name="style">display:none</xsl:attribute>
       &#160;
  </div>
</xsl:template>

<xsl:template match="TreeNode[@IsLeaf=1]">
      <table border="0" cellspacing="0" cellpadding="0">
           <xsl:attribute name="width"><xsl:eval>getWidth(this)</xsl:eval></xsl:attribute>
           <tr>
     	<td valign="middle" nowrap="nowrap">
          <xsl:eval no-entities="yes">getImgs(this)</xsl:eval><img>
                    <xsl:attribute name="src"><xsl:eval>getFirstImg(this,false)</xsl:eval></xsl:attribute>
     	       <xsl:attribute name="align">absmiddle</xsl:attribute>
     	       <xsl:attribute name="border">0</xsl:attribute>
     	    </img><img>
                    <xsl:attribute name="src"><xsl:eval>getSecImg(this,"item1.gif")</xsl:eval></xsl:attribute>
     	       <xsl:attribute name="align">absmiddle</xsl:attribute>
     	       <xsl:attribute name="border">0</xsl:attribute></img>
                 <xsl:choose>
                    <xsl:when test="@url">
                      <a>
                        <xsl:if test="@target">
			  <xsl:attribute name="target"><xsl:value-of select="@target" /></xsl:attribute>
			</xsl:if>
			<xsl:if test="@action">
			  <xsl:attribute name="onclick"><xsl:value-of select="@action" /></xsl:attribute>
                       </xsl:if>
                        <xsl:attribute name="tabindex">-1</xsl:attribute>
                        <xsl:attribute name="href"><xsl:value-of select="@url" /></xsl:attribute>
     		        <span type="label" style="cursor:handle">
		          <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		          <xsl:attribute name="type">label</xsl:attribute>
			  <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		          <xsl:value-of select="@caption" />
     		        </span>
                     </a>
                   </xsl:when>
     	           <xsl:when test="@action">
                     <a>
                       <xsl:attribute name="tabindex">-1</xsl:attribute>
     	               <xsl:attribute name="style">cursor:hand</xsl:attribute>
     	               <xsl:attribute name="href">#</xsl:attribute>
                       <xsl:attribute name="onclick"><xsl:value-of select="@action" /></xsl:attribute>
                       <span type="label" style="cursor:handle">
		         <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		         <xsl:attribute name="type">label</xsl:attribute>
			 <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		         <xsl:value-of select="@caption" />
     		      </span>
                     </a>
                   </xsl:when>
                   <xsl:otherwise>
                     <span type="label" style="cursor:handle">
		         <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		         <xsl:attribute name="type">label</xsl:attribute>
			 <xsl:attribute name="style">cursor:handle</xsl:attribute>
     		         <xsl:value-of select="@caption" />
     		     </span>
                   </xsl:otherwise>
                 </xsl:choose>
     	</td>
           </tr>
   </table>
</xsl:template>

<xsl:script><![CDATA[

var root=this.selectSingleNode("/Tree").getAttribute("imgpath");
var str1="<img src=\"";
var str2="\" align=\"absmiddle\" border=\"0\">";

function getFirstImg(_oSrc,flag)
{
    if(flag)
    {
       if(_oSrc.nextSibling==null) return pathImg("Lplus.gif");
       else return pathImg("Tplus.gif");
    }
    else
    {
       if(_oSrc.nextSibling==null) return pathImg("L.gif");
       else return pathImg("T.gif");
    }
}

function getSecImg(_oSrc,icon)
{
    var str=_oSrc.getAttribute("Icon");
    if(str==null || str=="")
       return pathImg(icon);
    else
       return str;
}
function getOpenSecImg(_oSrc,icon)
{
    var str=_oSrc.getAttribute("Icon");
    if(str==null || str=="")
    {
       str=icon;
       return pathImg("open"+str);
    }
    else
    {
      var strTmp = str.toLowerCase();
      if (strTmp.lastIndexOf("_both")>=0) //
         return str;

      var index = str.lastIndexOf(".");
      if (index>=0)
         return str.substring(0, index) + "_open" + str.substring(index);
      else
         return str;
    }
}

function isLast(_oSrc)
{
    if(_oSrc.nextSibling==null) return "last";
    else return "null";
}

function isLeaf(_oSrc)
{
    if(_oSrc.childNodes!=null && _oSrc.childNodes.length>0) return true;
    else return false;
}

function pathImg( __strImg )
{
	path = root + __strImg;
	return path;
}

function getImg(_flag)
{
    if(_flag=="1") return str1+pathImg("I.gif")+str2;
    else return str1+pathImg("white.gif")+str2;
}

function getImgs(_oSrc)
{
    imgText="";
    var ch=null;
    var poss=_oSrc.getAttribute("pre");
    for(i=0;i<poss.length;i++)
    {
       ch=poss.substring(i,i+1);
       imgText=imgText+getImg(ch);
    }
    return imgText;
}

function getWidth(_oSrc)
{
    var level=_oSrc.getAttribute("pre").length+2;
    var c_len=_oSrc.getAttribute("caption").length;;
    return level*26+c_len*11;
}
]]></xsl:script>


</xsl:stylesheet>
